package com.ld.security.server.admin.modules.ge.po;

import com.ld.security.common.core.base.column.ListString;
import com.ld.security.common.core.util.ReflectionUtil;
import com.ld.security.common.core.util.StringUtil;
import com.ld.security.common.mybatis.anno.QueryKey;
import com.ld.security.common.mybatis.anno.RemoveKey;
import com.ld.security.common.mybatis.anno.SqlKey;
import com.ld.security.common.mybatis.base.vo.ProxyVo;
import com.ld.security.common.mybatis.constant.SqlCondition;
import com.ld.security.server.admin.modules.ge.entity.*;
import com.ld.security.common.core.base.SuperPo;
import com.ld.security.common.mybatis.anno.SaveKey;
import com.ld.security.server.admin.modules.ge.vo.EarlyDetailsVo;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class SaveModelPo implements SuperPo ,ProxyVo {


    @SaveKey
    private GeModelEntity model;

    @SaveKey(name = "modelId",valueField = "model.id")
    private List<GeFieldEntity> fields;


    @SaveKey(name = "modelId",valueField = "model.id")
    private List<GeLinkEntity> links;

    @SaveKey(name = "modelId",valueField = "model.id")
    private List<GeChartEntity> charts;

    private List<EarlyDetailsVo.EarlyDetails> earlyModels;



    @Override
    public void saveBefore() {
        int i = 0;
        if(ReflectionUtil.isNull( model.getTableIds())){
            model.setTableIds(new ListString());
        }

        fields.sort((x,y) -> {
            return x.getSortVal() - y.getSortVal();
        });

        for (GeFieldEntity field : fields) {
            field.setSortVal(i);
            i+=2;
        }



    }
}
